package com.qf.chinatelcom.smsatragety.stragety;

import com.qf.chinatelcom.smsatragety.cache.BlackListCache;
import com.qf.chinatelcom.smsatragety.filter.DuTyFilter;
import com.qianfeng.smsplatform.common.constants.InterfaceExceptionDict;
import com.qianfeng.smsplatform.common.model.Standard_Submit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;



@Component
public class BlackFilter implements DuTyFilter {

    private static final Logger LOGGER = LoggerFactory.getLogger(BlackFilter.class);

    private BlackListCache blackListCache;

    @Autowired
    public void setBlackListCache(BlackListCache blackListCache) {
        this.blackListCache = blackListCache;
    }

    @Override
    public boolean dealSms(Standard_Submit submit) {
        String destMobile = submit.getDestMobile();//获取到所有的手机号
        if (blackListCache.isBlack(destMobile)){
            LOGGER.error("当前手机号{}在黑名单中",destMobile);
            submit.setDescription("当前手机号："+destMobile+"在黑名单中");
            submit.setErrorCode(InterfaceExceptionDict.RETURN_STATUS_BLACK_ERROR+"");//失败的状态码
            submit.setReportState(2);//失败的标识为
            return false;
        }else{
            LOGGER.error("当前手机号{}不在黑名单中",destMobile);
            return true;
        }
    }
}
